<template>
  <ElFormItem prop="defaultValue" label="默认值">
    <Select
      v-model="elProps.defaultValue"
      v-bind="getElProps"
      :options="options"
      label-name="dictLabel"
      value-name="dictValue"
      clearable
    ></Select>
  </ElFormItem>
</template>
<script setup lang="ts" name="SelectDefaultValueEditor">
import { ElFormItem } from "element-plus";
import { computed, ref, watch } from "vue";
import { Select } from "@/components/Form";
import dictDataApi from "@/views/system/dict-data/api";
const props = defineProps({
  elProps: {
    type: Object
  }
});
const getElProps = computed(() => {
  return { ...props.elProps, clearable: true };
});
const options = ref([]);
watch(
  () => props.elProps!.dictType,
  async dictType => {
    if (dictType) {
      options.value = await dictDataApi.list({ dictType });
    } else {
      options.value = [];
    }
  },
  {
    immediate: true
  }
);
</script>
